package cn.demomaster.quickui.view.banner;

import android.util.Log;
import android.view.View;

import androidx.viewpager2.widget.ViewPager2;

import cn.demomaster.quicklogger.QdLog;

public class ScaleTransformer implements ViewPager2.PageTransformer {
    private static final String TAG = "ScaleTransformer";
    private static float MIN_SCALE = 0.90f;
    private static final float MIN_ALPHA = 0.99f;

    public ScaleTransformer() {
    }
    public ScaleTransformer(float minScale) {
        MIN_SCALE = minScale;
    }
    @Override
    public void transformPage(View page, float position) {
        if (position < -1 || position > 1) {
            page.setAlpha(MIN_ALPHA);
            page.setScaleX(MIN_SCALE);
            page.setScaleY(MIN_SCALE);
        } else if (position <= 1) { // [-1,1]
            float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
            if (position < 0) {
                float scaleX = 1 + (1-MIN_SCALE) * position;
                page.setScaleX(scaleX);
                page.setScaleY(scaleX);
            } else {
                float scaleX = 1 - (1-MIN_SCALE) * position;
                page.setScaleX(scaleX);
                page.setScaleY(scaleX);
            }
            //page.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
        }
    }
}
